package TwentyFour;

import java.io.BufferedReader;
import java.io.InputStreamReader;

class TwentyFour {
    public static void main(String[] args){
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String line;
        try{
            System.out.println("铭铭24点计算器：");
            while((line=br.readLine())!=null){
                try{
                    if ("exit".equals(line)) break;

                    String[] s=line.split("\\s");
                    int[] v=new int[4];
                    for(int idx=0;idx<4;idx++) {
                        v[idx]=Integer.parseInt(s[idx]);
                        if (v[idx]<=0||v[idx]>=10) throw new Exception("Input error.");
                    }
                    evaluate(v);

                }catch(Exception ex){
                    ex.printStackTrace();
                }
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

    public static void evaluate(int[] v){
        int idx=0;
        for(int a=0;a<4;a++)
            for(int b=0;b<4;b++)
                for (int c=0;c<4;c++)
                    for (int d=0;d<4;d++){
                        if (a!=b && a!=c && a!=d && b!=c && b!=d && c!=d){
                            idx++;
                            check(v,new int[]{a,b,c,d});
                        }
                    }
    }
    static char[] op={'+','-','*','/'};
    public static void check(int[] v,int[] idx){

    for(int o=0;o<4;o++){
            for(int p=0;p<4;p++){
                for(int t=0;t<4;t++){
                    if (calc(op[p], calc(op[o],v[idx[0]],v[idx[1]]), calc(op[t],v[idx[2]],v[idx[3]]))==24){
                        System.out.println(String.format("(%1$d %2$c %3$d) %4$c (%5$d %6$c %7$d)",
                                v[idx[0]],op[o],v[idx[1]],op[p],v[idx[2]],op[t],v[idx[3]]));
                    }
                }
            }
        }
    }

    public static int calc(char op, int v1, int v2){
        switch(op){
            case '+':
                return v1+v2;
            case '-':
                return v1-v2;
            case '*':
                return v1*v2;
            case '/':
                if (v2==0) return -111;
                if (v1%v2!=0) return -111;
                return v1/v2;
            default:
                return 0;
        }
    }
}